package com.hxq.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hxq.domain.entity.User2;
import com.hxq.mapper.User2Mapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@RequiredArgsConstructor
public class User2Service extends ServiceImpl<User2Mapper, User2> {


    @Transactional(propagation = Propagation.REQUIRED)
    public void addRequired(User2 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void addRequiredException(User2 user){
        baseMapper.insert(user);
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void addRequiresNew(User2 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void addRequiresNewException(User2 user2) {
        baseMapper.insert(user2);
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.NESTED)
    public void addNested(User2 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.NESTED)
    public void addNestedException(User2 user){
        baseMapper.insert(user);
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public void addSupportsException(User2 user){
        baseMapper.insert(user);
        throw new RuntimeException();
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    public void addSupports(User2 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void addNotSupported(User2 user){
        baseMapper.insert(user);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public void addNotSupportedException(User2 user){
        baseMapper.insert(user);
        throw new RuntimeException();
    }
}
